#ifndef __MAIN__
#define __MAIN__

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "CommandParser.h"

#endif

CommandParser::CommandParser(int argc, char* argv[]){
	
	int c;
    
	opterr = 0;
    
	while ((c = getopt (argc, argv, "m:w:s:t:g:?")) != -1)
		switch (c)
		{
			case 'm':
				mapvalue = optarg;
				break;
			case 'w':
				windowvalue = optarg;
				break;
			case 's':
				stepvalue = optarg;
				break;
			case 't':
				modevalue = optarg;
				break;
			case 'g':
				genelistvalue = optarg;
				break;
			case '?':
				if (isprint (optopt))
					fprintf (stderr, "Unknown option `-%c'.\n", optopt);
				else
					fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
				break;
			default:
    			abort ();
         }
	// check validity of argument
	if (modevalue == NULL){
		fprintf(stderr, "Have to specify a mode.\n");
		exit(1);
	}
	else if (strcmp(modevalue, "gene") == 0){
		if (genelistvalue == NULL){
			fprintf(stderr, "Gene list needed for gene mode.\n");
			exit(1);
		}
	}
	else if (strcmp(modevalue, "physical") == 0 || strcmp(modevalue, "marker") == 0){
		if (windowvalue == NULL || stepvalue == NULL){
			fprintf(stderr, "Have to define both window and step size when using physical or marker mode.\n");
			exit(1);
		}
	}
	else {
		fprintf(stderr, "Undefined Mode.\n");
		exit(1);
	}
}
